﻿using System;
using __ts.Core.Api;
using __ts.Core.FilterChain;
using __ts.Core.Util.IO;

/*
 *  author: able
 *  @2012/2/21 10:31:58
 * 
 */
namespace __ts.Core.Filter.Codec
{
    /// <summary>
    /// 
    /// </summary>
    public interface ProtocolDecoder
    {
        /**
         * Decodes binary or protocol-specific content into higher-level message objects.
         * MINA invokes {@link #decode(IoSession, IoBuffer, ProtocolDecoderOutput)}
         * method with read data, and then the decoder implementation puts decoded
         * messages into {@link ProtocolDecoderOutput}.
         *
         * @throws Exception if the read data violated protocol specification
         */
        Object decode(IoSession session, StreamBuffer buf, ReadFilterChainController controller);// throws Exception;

        /**
         * Invoked when the specified <tt>session</tt> is closed.  This method is useful
         * when you deal with the protocol which doesn't specify the length of a message
         * such as HTTP response without <tt>content-length</tt> header. Implement this
         * method to process the remaining data that {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}
         * method didn't process completely.
         *
         * @throws Exception if the read data violated protocol specification
         */
        Object finishDecode(IoSession session);

        /**
         * Releases all resources related with this decoder.
         *
         * @throws Exception if failed to dispose all resources
         */
        void dispose(IoSession session);
    }
}